package com.njupt.simulation.utils;

/**
 * 计算链路夹角
 */
public class CaculateAngle {

    /**
     * @param coordinates1 夹角所指的卫星或地球站
     * @param coordinates2 场景中另外两个卫星或两个地球站中其中的一个
     * @param coordinates3 场景中另外两个卫星或两个地球站中其中的一个
     * @return  两个向量之间的夹角
     */
    public static double calculateangles(double[] coordinates1, double[] coordinates2,double[] coordinates3) {
        //coordinates1[0]经度  coordinates1[1]纬度  coordinates1[2]高度
        //coordinates2[0]经度  coordinates2[1]纬度  coordinates2[2]高度



        double[] Object1 = CoordinateTransform.coordinatetransform(coordinates1[0], coordinates1[1], coordinates1[2]);
        double[] Object2 = CoordinateTransform.coordinatetransform(coordinates2[0], coordinates2[1], coordinates2[2]);
        double[] Object3 = CoordinateTransform.coordinatetransform(coordinates3[0], coordinates3[1], coordinates3[2]);

        //获取对象1转换之后的坐标
        double x1 = Object1[0];
        double y1 = Object1[1];
        double z1 = Object1[2];
        //获取对象2转换之后的坐标
        double x2 = Object2[0];
        double y2 = Object2[1];
        double z2 = Object2[2];
        //获取对象3转换之后的坐标
        double x3 = Object3[0];
        double y3 = Object3[1];
        double z3 = Object3[2];

        double vector = x1*x3+y1*y3+z1*z3;
        double mold1 = Math.sqrt(Math.pow(x1,2)+Math.pow(y1,2)+Math.pow(z1,2));
        double mold3 = Math.sqrt(Math.pow(x3,2)+Math.pow(y3,2)+Math.pow(z3,2));

        double cosEL = vector/(mold1*mold3);
        double El = Math.acos(cosEL);
        return Math.toDegrees(El);

    }


        public static void main(String[] args) {

            double[] earthA= {117.26384496447895,33.331510471221065,551.2617030539741};
            double[] satB= {117.5,28,0.577};
            double[] satA={117,28.3,0.388};
            double[] satC= {146.253,0.134,35786};
            double[] earthC= {146.024,0.238,0.0679};
            double[] earthB= {149.030,0.160,0.0621};

        double angle1 = calculateangles(earthA,satA,satB);
        double angle2 = calculateangles(earthB,satA,satB);
        double angle3 = calculateangles(satA,earthA,earthC);
        double angle4 = calculateangles(earthC,satA,satC);
            // 打印结果
            System.out.println("夹角1为: " + angle1);
            System.out.println("夹角2为: " + angle2);
            System.out.println("夹角3为: " + angle3);
            System.out.println("夹角4为: " + angle4);
        }

}